{% extends base.html %}

{% block head %}
<script type="text/javascript" src="/static/lib/csv.js/csv.js"></script>
<script type="text/javascript" src="/static/lib/marked/marked.js"></script>
<script type="text/javascript" src="/static/js/marked-ext.js"></script>
<style>
.CodeMirror {
    width: 60rem;
    font-size:16px;
    height: auto;
}

#markdown-input {
    font-family: monospace;
}

blockquote {
    display: block;
    border-left: 8px solid #d0e5f2;
    padding: 5px 10px;
    margin: 10px 0;
    line-height: 1.4;
    font-size: 100%;
    background-color: #f1f1f1;
}

.marked-img {
    text-align: center;
}

.small {
    font-size: small;
}

img {
    max-width: 100%;
}

.alert {
    color: red;
    background-color: #FFCCCC;
    width: initial;
}

.x-code-block {
    font-family: Consolas,monospace;
    word-wrap: break-word;
    border-style: solid;
    border-radius: 3px;
    border-width: 1px;
    padding: 3px;
    background-color: #ffffcc;
}

.bottom-fixed-pannel {
    background-color: white; 
    position: fixed; 
    padding-bottom: 5px; 
    padding-top:5px; 
    bottom: 0px; 
    z-index: 100
}

.marked-heading {
    /* 避免顶部fixed菜单遮挡 */
    padding-top: 50px;
    margin-top: -50px;
}

.pathlist {
    background-color: #eee;
    padding:3px;
    box-sizing: border-box;
}

.hover {
    color: #AAA;
}

.hover:hover {
    color: #000;
}

.no-border tr td {
    border: none;
}

#uploadIframe {
    border: none;
    width: 100%;
    height: 60px;
}

#markdown-output-div img {
    max-height: 600px;
}

</style>
{% end %}


{% block body %}
    {% init file_type = "md" %}
    {% init pathlist = [] %}
    {% init file = None %}
    {% init show_search_div = True %}
    {% init show_add_file = False %}
    {% init show_add_group = False %}
    {% init show_path_list = True %}

    {% if file != None %}
        {% set globals()['file_type'] = file.type %}
        {% set globals()['file_id'] = file.id %}
    {% end %}

    {% if show_search_div %}
        <!-- {% include "search.html" %} -->
    {% end %}

    {% if show_add_file or show_add_group %}
    <div class="col-md-12" style="padding-bottom: 5px;">
        {% if _has_login %}
        <div class="left" style="float: left;">
            <a class="link" href="/note/add?parent_id={{file_id}}">记笔记</a>
            <a class="link prompt-btn" message="分组名" 
                    action="/note/add?type=group&parent_id={{file_id}}&name=">加分组</a>
        </div>
        {% end %}
    </div>
    {% end %}
    
    {% if show_path_list %}
    <div class="col-md-12 pathlist">
        <a href="/note/group">Home</a> /
        {% for item in pathlist %}
            <a href="{{item.url}}">{{ item.name }}</a> /
        {% end %}
    </div>
    {% end %}

    {% comment 如果有新类型的文件，继续增加file_type即可，后台实现不用变更 %}

    {% if file_type == "md" or file_type == "text" %}
        {% include "note/markdown.html" %}
    {% elif file_type == "table" %}
        {% include "note/table.html" %}
    {% elif file_type == "group" %}
        {% include "note/group.html" %}
    {% elif file_type == "group_list" %}
        {% include "note/group_list.html" %}
    {% else %}
        {% include "note/post.html" %}
    {% end %}

<script type="text/javascript">
function rename(id, oldName) {
    var newName = prompt("新名称", oldName);
    console.log(newName);
    if (newName != "" && newName != null) {
        $.post("/file/rename", {id:id, name:newName}, function (resp) {
            var code = resp.code;
            if (code != "success") {
                alert(resp.message);
            } else {
                // $("#file-"+id).text(newName);
                window.location.reload();
            }
        })
    }
}

function remove(id, name, parentId) {
    var confirmed = confirm("确定删除'" + name + "'?");
    if (confirmed) {
        $.post("/file/remove", {id:id}, function (resp) {
            var code = resp.code;
            if (code != "success") {
                alert(resp.message);
            } else {
                if (parentId) {
                    window.location.href="/file/view?id="+parentId;
                } else {
                    window.location.reload();
                }
            }
        })
    }
}

function moveTo(selfId, parentId) {
    $.post("/file/group/move", 
        {id:selfId, parent_id: parentId}, 
        function (resp){
            console.log(resp);
            window.location.reload();
    });
}
</script>

{% end %}

